// pages/manifest_task_history/manifest_task_history.js
var app = getApp()
var page = 0;
var page_size = 5
var header = {};

var GetList = function (that) {
  that.setData({
    hidden: false
  });
  wx.request({
    url: 'https://119.3.46.145/server/GetMissionHistory?userid=' + app.globalData.userid + '&start=' + page_size * page + '&num=' + page_size,
    method: 'post',
    header: header,
    success: function (res) {
      let data = JSON.parse(res.data.data);
      //console.log(data, "data");
      if (data.length == 0) {
        that.setData({
          hidden: true
        });

        return;
      }
      var tmp_list = that.data.list;
      for (var i = 0; i < data.length; i++) {
        tmp_list.push(data[i]);
      }
      that.setData({
        list: tmp_list
      });
      page++;
      that.setData({
        hidden: true
      });
    }
  });
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hidden: true,
    list: [],
    scrollTop: 0,
    scrollHeight: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    header = {
      'content-type': 'application/x-www-form-urlencoded',
      'cookie': "openid=" + app.globalData.openid
    }

    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        //console.info(res.windowHeight);
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
  },

  bindDownLoad: function () {
    var that = this;
    GetList(that);
  },

  scroll: function (event) {
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },

  refresh: function (event) {
    page = 0;
    this.setData({
      list: [],
      scrollTop: 0
    });
    GetList(this)
  },

  onPullDownRefresh: function () {
   //console.log("下拉")
  },

  onReachBottom: function () {
    //console.log("上拉");
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    GetList(that);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})